<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Get_function extends CI_Model {
	
	function getCurrentDatetime() {
		$dateTime = new DateTime("now", new DateTimeZone('Europe/Warsaw'));
		//$dateTime->format("Y-m-d H:i:s");
		//print_r($dateTime);
		return $dateTime->format("Y-m-d H:i:s");
	}
	
	function getCurrentToNumberDateTime() {
		$date = new DateTime("now", new DateTimeZone('Europe/Warsaw'));
		//$dateTime->format("Y-m-d H:i:s");
		//print_r($dateTime);
		return $date->format("YmdHis");
	}
	
	function addToLog($fileName, $text, $userName) {
		try {
			if (!file_exists('logs/'.$fileName)) {
				throw new Exception('nie istnieje plik o nazwie "<b>'. $fileName .'</b>"');
			}
			$file = fopen('logs/'.$fileName, 'a');
			$br = "\r\n"; // For NewLine ....Its Working wel.................
		
			//$stringData = $comp_code.$junc_sno;
			fwrite($file, $this->getCurrentDatetime().' - '.$userName.' - '.$text.$br);
			fclose($file);
		} 
		catch (Exception $e) {
			$message['message'] = $e->getMessage();
			$this->load->view('vError', $message);
		}
	}
	
	function clearFile($fileName, $path=null) {
		if ($path == null)	{
			$directory = $fileName;
		} else {
			$directory = $path.$fileName;
		}
		fopen($directory, 'w');		
	}
	
	function run() {
		
	}
	
	
	function createFolder($path) {
		if (!file_exists($path)) {
	    	mkdir($path, 0777, true);
		}
	}
}
